package com.niu.wm.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.niu.wm.service.BaseService;
import com.niu.wm.service.DictService;
import com.niu.wm.core.error.BizException;
import com.niu.wm.core.error.GlobalErrorCode;
import com.niu.wm.dao.mapper.DictMapper;
import com.niu.wm.model.User;
import com.niu.wm.model.Dict;

@Service
public class DictServiceImpl extends BaseService implements DictService {
	
    @Autowired
    private DictMapper  dictMapper;
	
    
    @Override
	public Dict load(Long id){
		return load(id,null);
	}
    
    @Override
	public Dict loadByCode(String code){
    	return load(null, code);
	}
    
    private Dict load(Long id, String code){
    	
    	if(null != id )
    		return dictMapper.selectById(id);
        else 
        	return dictMapper.selectByCode(code);
    }
    
    @Override
	public int add(User user, Dict dict){
    	
		return dictMapper.insert(dict);
	}
    
    @Override
	public void delete(User user, Long id){
		dictMapper.delete(id);
	}
    
    @Override
	public int update(User user, Dict dict){
		int count = dictMapper.update(dict);	
		
		return count;
	}
}
